﻿<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="../helpproject.xsl" ?>
<topic template="Default" lasteditedby="Geert" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../helpproject.xsd">
  <title translate="true">Data handling</title>
  <keywords>
    <keyword translate="true">Data</keyword>
    <keyword translate="true">Data handling</keyword>
  </keywords>
  <body>
    <header>
      <para styleclass="Heading1"><text styleclass="Heading1" translate="true">Data handling</text></para>
    </header>
    <para styleclass="Normal"><text styleclass="Normal" translate="true">This part of the documentation is all about data handling the way it should that is available via Catel. Some parts are based on </text><link displaytype="text" defaultstyle="true" type="weblink" href="http://www.codeproject.com/KB/WPF/Catel.aspx" target="_blank" styleclass="Normal" translate="true">the article on Code Project</link><text styleclass="Normal" translate="true">, but this documentation is more up-to-date.</text></para>
    <para styleclass="Normal"><text styleclass="Normal" translate="true">The first thing that is important is that lots of developers lose way too much time writing custom serializable objects. Serialization is a field of expertise, and only a handful of developers I know really master the serialization of objects (think of version changes of the assembly, class changes (new or removed properties), etc.). Most developers think they master serialization by creating a BinaryFormatter object like the code belows show:</text></para>
    <para styleclass="Code Example"><text styleclass="Code Example" translate="true">BinaryFormatter serializer = new BinaryFormatter();</text><br/><text styleclass="Code Example" translate="true">var myObject = (MyObject)serializer.Deserialize(stream);</text></para>
    <para styleclass="Normal"><text styleclass="Normal" translate="true">Most developers don’t know that reflection breaks when:</text></para>
    <list id="1" type="ol" listtype="decimal" formatstring="&#37;&#48;&#58;&#115;&#46;" format-charset="DEFAULT_CHARSET" levelreset="true" legalstyle="false" startfrom="1" styleclass="Normal (list)" style="font-family:Arial; font-size:10pt; color:#000000;">
      <li styleclass="Normal (list)"><text styleclass="Normal (list)" translate="true">You change the version number of your assembly;</text></li>
      <li styleclass="Normal (list)"><text styleclass="Normal (list)" translate="true">You add or remove a property or field;</text></li>
      <li styleclass="Normal (list)"><text styleclass="Normal (list)" translate="true">You add or remove an event.</text></li>
    </list>
    <para styleclass="Normal"><text styleclass="Normal" translate="true">And even if you know, it takes a lot of knowledge and courage to start beating the beast of burden. Like every developer, I also encountered this and was writing backwards compatibility code until I had enough of it and decided to master the field of serialization. The result is the </text><link displaytype="text" defaultstyle="true" type="topiclink" href="T_Catel_Data_ModelBase" styleclass="Normal" translate="true">ModelBase</link><text styleclass="Normal" translate="true"> class, which can be used as a base class for all data objects that need to be held in memory and maybe serialized to disk (or a stream, or XML, or ...).</text></para>
  </body>
</topic>
